package generadorDescriptores.test;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;

import generadorDescriptores.AttributesData;
import generadorDescriptores.dom.XmlDocument;

public class PruebaJoins {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		XmlDocument xml = new XmlDocument();
		Document doc = xml.getDocument();
		AttributesData data = new AttributesData();
		data.setBiName("sales");
		data.setFacttableTable("sale");
		data.setJoinName("join1");
		data.setConditionJoinColumn("sale");
		data.setConditionJoinFactColumn("facttable.id");
		
		xml.buildDescriptorAndFacttable(data);
		xml.addConditionToJoin("join1", data);
		
		NodeList list = xml.getDocument().getElementsByTagName("join");
		for (int i = 0; i < list.getLength(); i++) {
			if(list.item(i).getAttributes().getNamedItem("name").getNodeValue().equals("join1"))
				System.out.println("Hola tarola");
		}
		
		xml.addConditionToJoin("join1", data);
		
		
		
		OutputFormat format = new OutputFormat(doc);
		format.setIndenting(true);
		format.setIndent(4);
		format.setStandalone(false);
		format.setEncoding("iso-8859-1");
		TransformerFactory xformFactory 
	       = TransformerFactory.newInstance();  
	      Transformer idTransform  = null;
		try {
			idTransform = xformFactory.newTransformer();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		}
	      Source input = new DOMSource(doc);
	      Result output = new StreamResult(System.out);
	      try {
			idTransform.transform(input, output);
		} catch (TransformerException e) {
			e.printStackTrace();
		}
		
		System.out.println("fin");
	}

}
